/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.qjs.smterp.model;

import java.util.Set;

import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Vostro 3400
 */
@Entity
@Table(name = "tb_unit")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Unit.findAll", query = "SELECT t FROM Unit t"),
    @NamedQuery(name = "Unit.findByUnitId", query = "SELECT t FROM Unit t WHERE t.unitId = :unitId"),
    @NamedQuery(name = "Unit.findByUnitCode", query = "SELECT t FROM Unit t WHERE t.unitCode = :unitCode"),
    @NamedQuery(name = "Unit.findByUnitName", query = "SELECT t FROM Unit t WHERE t.unitName = :unitName")})
public class Unit extends BasePojo {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "UNIT_ID")
    private Integer unitId;
    @Basic(optional = false)
    @Column(name = "UNIT_CODE")
    private String unitCode;
    @Column(name = "UNIT_NAME")
    private String unitName;
    @Column(name = "DESCRIPTION")
    private String description;


    //@OneToMany(fetch = FetchType.LAZY, mappedBy = "unit")
    @OneToMany(cascade = CascadeType.ALL)
    @JoinColumn(name="UNIT_ID")
    private Set<GoodsInstock> goodsInstock;
    
    public Unit() {
    }

    public Unit(Integer unitId) {
        this.unitId = unitId;
    }

    public Unit(Integer unitId, String unitCode) {
        this.unitId = unitId;
        this.unitCode = unitCode;
    }

    public Integer getUnitId() {
        return unitId;
    }

    public void setUnitId(Integer unitId) {
        this.unitId = unitId;
    }

    public String getUnitCode() {
        return unitCode;
    }

    public void setUnitCode(String unitCode) {
        this.unitCode = unitCode;
    }

    public String getUnitName() {
        return unitName;
    }

    public void setUnitName(String unitName) {
        this.unitName = unitName;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Set<GoodsInstock> getGoodsInstock() {
		return goodsInstock;
	}

	public void setGoodsInstock(Set<GoodsInstock> goodsInstock) {
		this.goodsInstock = goodsInstock;
	}

	@Override
    public int hashCode() {
        int hash = 0;
        hash += (unitId != null ? unitId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Unit)) {
            return false;
        }
        Unit other = (Unit) object;
        if ((this.unitId == null && other.unitId != null) || (this.unitId != null && !this.unitId.equals(other.unitId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.qjs.smterp.model.TbUnit[ unitId=" + unitId + " ]";
    }
    
}
